package cn.bdqn.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Json {
    private Integer code; //状态码 200代表成功 400代表失败
    private String msg; //消息提示
    private Object data;   //数据
    private Integer total;  //数据总数
    private String token;   //全局拦截字符

    //无需分页调用该构造
    public Json(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    //分页调用该构造
    public Json(Integer code, String msg, Object data, Integer total) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.total = total;
    }
    //增删改使用该构造
    public Json(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public  static Json isEmpty(Object data){
        if(null==data){
            return new Json(400,"数据为空");
        }else {
            return new Json(200,"成功",data);
        }

    }


    public static Json ok(Object data){
      return   new Json(200,null,data,null,null);
    }
    public static Json ok(Object data,String token){
        return new Json(200,null,data,null,token);
    }
    public static Json ok(){
        return new Json(200,null);
    }
    public static Json fall(String msg){
        return new Json(400,msg,null,null,null);
    }

    public static Json fall(String msg,Integer code){
        return new Json(code,msg,null,null,null);
    }


}